////////////////////////////////////////////////////////////////////////////////

#ifndef _CIRCLECIRCLEINTERSECTOR_H_
#include "circlecircleintersector.h"
#endif

#ifndef _CIRCLE_H_
#include "circle.h"
#endif

#ifndef _MATHFUNCTIONS_H_
#include "mathfunctions.h"
#endif

////////////////////////////////////////////////////////////////////////////////


void CircleCircleIntersector::Intersect( PhysicalObject& _obj1, PhysicalObject& _obj2 )
{
    const PE::Circle& sh1 = static_cast<const PE::Circle&>(_obj1.GetShape());
    const PE::Circle& sh2 = static_cast<const PE::Circle&>(_obj2.GetShape());

    const PE::Point p1 = _obj1.GetPosition();
    const PE::Point p2 = _obj2.GetPosition();

    // Minimal allowed distance between two objects
    double minDist = sh1.m_Radius + sh2.m_Radius;

    // Current distance between two objects
    double curDist = PE::Distance(p1, p2);

    if ( curDist < minDist )
    {
        // Get impulse direction
        PE::Vector normal = {p1.x - p2.x, p1.y - p2.y};
        m_Normal = PE::GetDirection(normal);
        m_WasIntersection = true;
    }
    else
        m_WasIntersection = false;
}


////////////////////////////////////////////////////////////////////////////////
